package com.gcsoftware.web.mapper;

import com.gcsoftware.web.beans.T_GW_VERIFY;
import com.gcsoftware.web.mapper.providers.GwVerifyProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by qs on 2018/3/26.
 */
@Mapper
public interface T_GW_VERIFYMAPPER {

    @Insert("INSERT INTO T_GW_VERIFY(C_VERIFY_ID ,C_VERIFY_TYPE ,C_APP_ID ,C_INTERF_ID ,C_SUBMIT_USER_ID ,C_VERIFY_STATUS ,C_VERIFY_REMARK) VALUES(#{c_VERIFY_ID},#{c_VERIFY_TYPE},#{c_APP_ID},#{c_INTERF_ID},#{c_SUBMIT_USER},#{c_VERIFY_STATUS},#{c_VERIFY_REMARK})")
    public int insertVerify(T_GW_VERIFY verify);

    @SelectProvider(type=GwVerifyProvider.class, method="queryForList")
    public List<T_GW_VERIFY> queryForList(
            @Param(value = "c_VERIFY_TYPE") String c_VERIFY_TYPE,
            @Param(value = "c_VERIFY_STATUS") String c_VERIFY_STATUS);

    @Select("SELECT max(C_VERIFY_ID) FROM T_GW_VERIFY")
    public String getMaxId();

    @Update("UPDATE T_GW_VERIFY SET D_MODIFY_TIME = CURRENT_TIMESTAMP(),c_VERIFY_USER_ID = #{c_VERIFY_USER_ID},c_VERIFY_STATUS=#{c_VERIFY_STATUS} WHERE c_VERIFY_ID=#{c_VERIFY_ID} and c_VERIFY_STATUS!='VERIFY_STATUS_UNABLE'")
    public int updateVerify(@Param(value = "c_VERIFY_USER_ID") String c_VERIFY_USER_ID,@Param(value = "c_VERIFY_STATUS") String c_VERIFY_STATUS,@Param(value = "c_VERIFY_ID") String c_VERIFY_ID);

    @Update("<script>" +
            "UPDATE " +
                "t_GW_VERIFY " +
            "SET " +
                "D_MODIFY_TIME = CURRENT_TIMESTAMP() , " +
                "c_VERIFY_STATUS='VERIFY_STATUS_UNABLE' " +
            "where " +
                "c_APP_ID = #{c_APP_ID} " +
                "AND c_VERIFY_TYPE =#{c_VERIFY_TYPE} "+
                "<when test='null!=c_INTERF_ID'>AND c_INTERF_ID = #{c_INTERF_ID} </when>" +
                "AND c_VERIFY_STATUS='VERIFY_STATUS_UNVERIFY'</script>")
    public int unableVerify(
            @Param(value = "c_APP_ID")String c_APP_ID,
            @Param(value = "c_INTERF_ID") String c_INTERF_ID,
            @Param(value = "c_VERIFY_TYPE") String c_VERIFY_TYPE);

    @Select("SELECT c_VERIFY_ID,vri.c_APP_ID,usr.C_COMPANY_ID ,c_INTERF_ID,c_VERIFY_TYPE,c_SUBMIT_USER_ID c_SUBMIT_USER,c_VERIFY_REMARK FROM T_GW_VERIFY vri,T_COM_SYS_USER  usr where usr.C_USER_ID  = vri.C_SUBMIT_USER_ID  AND  C_VERIFY_ID = #{c_VERIFY_ID}")
    public T_GW_VERIFY getById(@Param(value = "c_VERIFY_ID") String c_VERIFY_ID);
}
